package com.xxgc.ssm.service.impl;

import com.xxgc.ssm.dao.UsersMapper;
import com.xxgc.ssm.po.Users;
import com.xxgc.ssm.po.UsersExample;
import com.xxgc.ssm.po.info.Info;
import com.xxgc.ssm.service.IUserLogin;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * 用户登录业务逻辑
 * @Author SJY
 * @DATE 2021-12-7
 * 创建类
 * @Author SJY
 * @DATE 2021-12-20
 * 添加了什么什么功能
 * 修改了什么什么功能
 */
@Service
public class UserLoginService implements IUserLogin {

    @Autowired
    private UsersMapper um;
    @Autowired
    private Info info;

    public Info selectUserByNameAndPass(Users user, HttpSession session) {
        UsersExample usersExample = new UsersExample();
        usersExample.createCriteria().andUNameEqualTo(user.getUName()).andUPassEqualTo(user.getUPass());
        List<Users> users = um.selectByExample(usersExample);
        if(users.size()<1){
            info.setCode(-1);
            info.setMsg("用户名或密码错误");
        }else{
            info.setCode(200);
            info.setMsg("登陆成功");
            session.setAttribute("user",users.get(0));
        }
        return info;
    }
}
